Imports Liftoff.Samples.BusinessObjects

Public Class frmTestDataBindingSupport

#Region "Private Variables"
    Private myNewCustomer As Boolean
    Private myCustomersA As New List(Of Customer)
    Private myCustomersB As New List(Of Customer)
#End Region

#Region "Local Events"
    Private Sub frmTestWindows_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        My.Application.Log.WriteEntry("Start")
        Me.Text += String.Format("   ---   V {0}        current user  {1}", My.Application.Info.Version.ToString, My.User.Name)
        lblCopyright.Text = My.Application.Info.Copyright
        bsCustomersA.DataSource = myCustomersA
        bsCustomersB.DataSource = myCustomersB
    End Sub

    Private Sub cmdNewCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNewCustomer.Click
        bsCustomer.DataSource = New Customer
        myNewCustomer = True
    End Sub

    Private Sub cmdSaveCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveCustomer.Click
        bsCustomer.EndEdit()
        If myNewCustomer Then
            bsCustomersA.Add(bsCustomer.Current)
            bsCustomer.DataSource = New Customer
            myNewCustomer = True
        End If
    End Sub

    Private Sub cmdCancle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancle.Click
        bsCustomer.CancelEdit()
    End Sub

    Private Sub cmdDeleteCustomer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDeleteCustomer.Click
        If bsCustomersA.Current IsNot Nothing Then bsCustomersA.RemoveCurrent()
    End Sub

    'Link the selected customer to the customer's data input page
    Private Sub bsCustomersA_CurrentChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles bsCustomersA.CurrentChanged, lbxCustomers.DoubleClick
        If bsCustomersA.Current IsNot Nothing Then
            bsCustomer.DataSource = DirectCast(bsCustomersA.Current, Customer)
        Else
            bsCustomer.DataSource = GetType(Customer)
        End If
        myNewCustomer = False
    End Sub

    Private Sub cmdIncTurnoverPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdIncTurnoverPage.Click
        My.Application.Log.WriteEntry("--- Inc turnover")
        If bsCustomer.Current IsNot Nothing Then DirectCast(bsCustomer.Current, Customer).Turnover += 100
    End Sub

    Private Sub cmdIncTurnoverGrid_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdIncTurnoverGrid.Click
        My.Application.Log.WriteEntry("--- Inc turnover")
        If bsCustomersB.Current IsNot Nothing Then DirectCast(bsCustomersB.Current, Customer).Turnover += 100
    End Sub
#End Region

End Class
